package Client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class getAnotherPlayer
{
    public static String getOneHtml(String htmlurl)  {
        URL url;
        String temp;
        StringBuffer sb = new StringBuffer();
        try {
            url = new URL(htmlurl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));// 读取网页全部内容
            while ((temp = in.readLine()) != null) {
                sb.append(temp);
            }
            in.close();
        } catch (MalformedURLException me) {
            System.out.println("你输入的URL格式有问题！请仔细输入");
            me.getMessage();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // System.out.println(sb.toString()); //成功爬下了静态网页
        return sb.toString();
    }
    public static String sendGet(String url , int x,int y,int color,int dg,int isWin,int tc,int hm) {
        if(hm==-1)
        {
            url+="/getLogin";
        }
        else
        {
            url+="/gobangServlet?";
            url+=String.format("x=%d&y=%d&color=%d&dg=%d&isWin=%d&tc=%d&hm=%d",x,y,color,dg,isWin,tc,hm);
        }
        return getOneHtml(url);
    }


}